package com.xmh.util;

import com.xmh.SpringBootDemo1Application;
import com.xmh.demo.dao.UserDAO;
import com.xmh.demo.entity.UserEntity;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.stereotype.Component;
import org.springframework.test.context.junit4.SpringRunner;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Iterator;
import java.util.List;

@RunWith(SpringRunner.class)
@Component
@SpringBootTest(classes = SpringBootDemo1Application.class)
public class PersonnelThanUtil {

    @Autowired
    private UserDAO userDAO;

    private String names = "陈鸿铎\n" +
            "叶清浩\n" +
            "王蕾\n" +
            "余绍杰\n" +
            "肖明辉\n" +
            "申奥\n" +
            "贺子淇\n" +
            "梁佳伟\n" +
            "邝振辉\n" +
            "简丽琼\n" +
            "卢靖文\n" +
            "李昌荣\n" +
            "刘文辉\n" +
            "刘珧\n" +
            "李政\n" +
            "陈振林\n" +
            "申少龙\n" +
            "刘笃坤\n" +
            "陈伟健\n" +
            "徐晓云\n" +
            "廖利君\n" +
            "谢楚涛\n" +
            "姚保娟\n" +
            "冯华恒\n" +
            "曾秀勤\n" +
            "林培伟\n" +
            "张焘\n" +
            "吕飞俊\n" +
            "卢泽坤\n" +
            "陈江华\n" +
            "曾富强\n" +
            "李东辉\n" +
            "戚水仙\n" +
            "李秀珠\n" +
            "李挺\n" +
            "伍振飞\n" +
            "梁强\n" +
            "汤铭辉\n" +
            "余浩孟\n" +
            "曾文浩\n" +
            "陈泽章\n" +
            "温亦康\n" +
            "蒋琦\n" +
            "林德有";

    @Test
    public void PersonnelThan() {
        UserEntity userEntity = new UserEntity();
        userEntity.setUserEnabled(true);

        List<UserEntity> userEntities = userDAO.selectList(userEntity.toMap());

        Iterator<UserEntity> iterator = userEntities.iterator();
        while (iterator.hasNext()) {
            if (names.contains(iterator.next().getUsername())) {
                iterator.remove();
            }
        }

        userEntities.forEach(e -> System.out.print(e.getUsername() + " "));
        System.out.println();

        userEntity.setUserEnabled(false);
        List<UserEntity> userEntities2 = userDAO.selectList(userEntity.toMap());
        System.out.println("------------------------false user ------------------");
        userEntities2.forEach(e -> System.out.print(e.getUsername() + " "));
        System.out.println();
    }

    @Test
    public void PersonnelThan2() {
        UserEntity userEntity = new UserEntity();
        userEntity.setUserEnabled(true);
        List<UserEntity> userEntities = userDAO.selectList(userEntity.toMap());

        List<String> nameList = new ArrayList<>(Arrays.asList(names.split("\n")));

        Iterator<String> iterator = nameList.iterator();
        while (iterator.hasNext()) {
            String name = iterator.next();
            for (UserEntity entity : userEntities) {
                if (entity.getUsername().equals(name)) {
                    iterator.remove();
                    break;
                }
            }
        }
        System.out.println("让我看看是哪个龟孙没有录入数据库");
        nameList.forEach(System.out::println);
    }
}